home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 2D / Restore Screen Cluts / WindowPositioner.h < prev   
Encoding:
C/C++ Source or Header  |  2000-09-28  |  7.3 KB  |  156 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        WindowPositioner.h
  3.  
  4.     Contains:    Window-handling code for the ColorReset application
  5.  
  6.     Written by: Forrest Tanaka    
  7.  
  8.     Copyright:    Copyright © 1988-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/13/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #ifndef __WINDOWPOSITIONER__
  24. #define __WINDOWPOSITIONER__
  25.  
  26.  
  27. /******************************************************************************\
  28. * Header Files
  29. \******************************************************************************/
  30.  
  31. #ifndef THINK_C
  32. #ifndef __WINDOWS__
  33. #include <Windows.h>
  34. #endif
  35. #endif
  36.  
  37.  
  38. /******************************************************************************\
  39. * Constants
  40. \******************************************************************************/
  41.  
  42. #define kMainScreenPos   0 /* Position window against the main screen */
  43. #define kParentPos       1 /* Position window against parent window */
  44. #define kParentScreenPos 2 /* Position window against parent window’s screen */
  45.  
  46. #define kCenterPos  0 /* Position window centered on base rectangle */
  47. #define kAlertPos   1 /* Position window in alert position */
  48. #define kStaggerPos 2 /* Position window staggered from other windows */
  49.  
  50.  
  51. /******************************************************************************\
  52. * PositionScreenRect - Position a rectangle based on the screen set-up
  53. *
  54. * Whenever a window is to be positioned on a screen in an aesthetic or at least
  55. * unannoying way, PositionScreenRect is called to calculate a position for the
  56. * window that tries not to get on people’s nerves.  The position is returned as
  57. * a point in global coordinates at which the top-left corner of the portRect of
  58. * of the window being positioned should be placed.  The screenOption parameter
  59. * specifies which screen the window should appear on.  It has the following
  60. * values and meanings:
  61. *
  62. * kMainScreenPos   - Always position the window somewhere on the main screen.
  63. *
  64. * kParentPos       - Position the window within the portRect of the window
  65. *                    specified by parentWindow.  If parentWindow is nil, then
  66. *                    this parameter defaults to kMainScreenPos.
  67. *
  68. * kParentScreenPos - Position the window on the screen that contains most of the
  69. *                    area of the window specified by parentWindow.  If
  70. *                    parentWindow is nil or if Color QuickDraw isn’t available,
  71. *                    then this parameter defaults to kMainScreenPos.
  72. *
  73. * The positionOption parameter specifies how the window is to be positioned
  74. * within the screen (or parentWindow if screenOption == kParentPos).  It has the
  75. * following values and meanings:
  76. *
  77. * kCenterPos  - Center the window
  78. *
  79. * kAlertPos   - Position the window in alert position, that is, 1/3 of the
  80. *               screen is above the alert and 2/3 below it.
  81. *
  82. * kStaggerPos - Stagger the window from existing windows.  An attempt is made to
  83. *               position the window so that its portRect is in the upper-left
  84. *               corner of the screen (or parentWindow if screenOption ==
  85. *               kParentPos).  If the top-left corner of one or more windows is
  86. *               already in that general area, then another attempt is made down
  87. *               and to the right a bit.  These attempts are made either until
  88. *               an area that doesn’t collide with an existing window is found or
  89. *               no areas devoid of windows can be found.  If no free area was
  90. *               found, then attempts are made from the top-left corner again,
  91. *               but this time collisions are tolerated.  A position that has the
  92. *               fewest number of collisions is returned.
  93. *
  94. * The portRect of the window being positioned is normally passed in the
  95. * windowRect parameter.  Its actual coordinates don’t matter; PositionScreenRect
  96. * is only interested in its width and height.  If positionOption == kStaggerPos,
  97. * then PositionScreenRect won’t allow the portRect of a window to be staggered
  98. * right off of the screen or window it’s being positioned in.  If it’s OK for a
  99. * window to be staggered partly off of a screen or if the final size of the
  100. * window depends on the position that PositionScreenRect returns, then
  101. * windowRect should specify the smallest rectangle that would be allowed to be
  102. * visible when the window is placed at the location that PositionScreenRect
  103. * returns.  In other words, if you want PositionScreenRect to guarantee that at
  104. * least the top-left 100 x 100 pixels of the window being positioned are visible
  105. * when it’s placed at the location that PositionScreenRect returns, then
  106. * windowRect should be 100 x 100 pixels.
  107. *
  108. * parentWindow specifies the window that the positioned window is based on.  See
  109. * the description of the screenOption parameter for details.  If screenOption ==
  110. * kMainScreen, then parentWindow is ignored.
  111. *
  112. * hBias and vBias are only used if positionOption == kStaggerPos.  They specify
  113. * the horizontal and vertical amounts to offset the returned position.  The
  114. * number of pixels between the top of the portRect of the window being
  115. * positioned and the top of the window’s frame should be passed in vBias.
  116. * Likewise, the number of pixels between the left edge of the window’s portRect
  117. * and the left edge of the window’s frame should be passed in hBias.  This is
  118. * normally used to take into account the amount of space taken up by the title
  119. * bar of the window being positioned.  You can use CalcWindowBias to have the
  120. * bias calculated for you.
  121. \******************************************************************************/
  122.  
  123. void PositionScreenRect(
  124.     Rect      *modWindowRect,
  125.     short     screenOption,
  126.     short     positionOption,
  127.     WindowPtr parentWindow,
  128.     short     hBias,
  129.     short     vBias);
  130.  
  131.  
  132. /******************************************************************************\
  133. * CalcWindowBias - Calculate the bias for a specific kind of window
  134. *
  135. * This routine calculates and returns the bias for the kind of window whose
  136. * window proc ID is given in the procID parameter.  The bias’s horizontal
  137. * coordinate can then be passed in the hBias parameter of PositionScreenRect and
  138. * the vertical coordinate can be passed in the vBias parameter.  This is so that
  139. * windows can be staggered while taking into account the size of the title bar
  140. * of a window and other parts of the window frame.  The "bias" is just my
  141. * (actually Craig’s) word for the vertical and horizontal distance between the
  142. * top-left coordinate of the rgnBBox of the content region of a window and the
  143. * top-left coordinate of the rgnBBox of the structure region of that same
  144. * window.
  145. *
  146. * If the window being positioned has a go-away box, then true is passed in the
  147. * goAwayFlag parameter, otherwise false is passed.
  148. \******************************************************************************/
  149.  
  150. Point CalcWindowBias(
  151.     short   procID,
  152.     Boolean goAwayFlag);
  153.  
  154.  
  155. #endif
  156.